package org.example.application;

import cn.hutool.core.text.CharSequenceUtil;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.context.SecurityContextHolder;
import org.example.domain.model.entity.url.UrlShortener;
import org.example.domain.model.entity.url.req.RecycleBinPageReq;
import org.example.domain.model.entity.url.req.RecycleBinReq;
import org.example.domain.model.service.RecycleBinDomainService;
import org.example.web.exception.ServerException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class RecycleBinService {
    private final RecycleBinDomainService recycleBinDomainService;

    public void saveRecycleBin(RecycleBinReq recycleBinReq) {
        recycleBinDomainService.saveRecycleBin(recycleBinReq);
    }

    public PageInfo<UrlShortener> recycleBinPage(RecycleBinPageReq recycleBinPageReq) {
        String userName = SecurityContextHolder.getUserName();
        if (CharSequenceUtil.isEmpty(userName)) {
            throw new ServerException("请先登录！");
        }
        return recycleBinDomainService.recycleBinPage(recycleBinPageReq, userName);
    }

    public void recoverRecycleBin(RecycleBinReq recycleBinReq) {
        recycleBinDomainService.recoverRecycleBin(recycleBinReq);
    }

    public void removeRecycleBin(RecycleBinReq recycleBinReq) {
        recycleBinDomainService.removeRecycleBin(recycleBinReq);
    }
}
